package com.ocom.payhandle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.card.EntiyXfMerchPayInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payhandle.dao.IDaoXfMerchPayInfo;
import com.ocom.payhandle.service.XfMerchPayInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class XfMerchPayInfoServiceImpl extends ServiceImpl<IDaoXfMerchPayInfo, EntiyXfMerchPayInfo> implements XfMerchPayInfoService {

    @Autowired
    private IDaoXfMerchPayInfo iDaoXfMerchPayInfo;

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId")
    @Override
    public EntiyXfMerchPayInfo selectConfigure(Long comId, Long merchId) {
        QueryWrapper<EntiyXfMerchPayInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("company_id","user_name","password","merch_id");
        queryWrapper.eq("com_id",comId);
        if (merchId==null){
            queryWrapper.eq("merch_id",0);
        }else {
            queryWrapper.eq("merch_id",merchId);
        }
        queryWrapper.orderByDesc("update_time");
        queryWrapper.last(" limit 1");
        return iDaoXfMerchPayInfo.selectOne(queryWrapper);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId")
    public EntiyXfMerchPayInfo selectConfigure(Long comId, String companyId) {
        QueryWrapper<EntiyXfMerchPayInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("company_id","user_name","password","merch_id");
        queryWrapper.eq("com_id",comId);
        queryWrapper.eq("company_id",companyId);
        queryWrapper.orderByDesc("update_time");
        queryWrapper.last(" limit 1");
        return iDaoXfMerchPayInfo.selectOne(queryWrapper);
    }
}
